<template>
  <div class="iphone">
    <h2>设置新密码</h2>
    <van-field clearable label="+86 ∨" label-width="50" placeholder="请输入您的手机号码" v-model="username" />
    <van-field clearable placeholder="请输入6-20位非特殊符号的组合" type="password" v-model="password" />

    <van-button :disabled="true&&isflay" @click="sub_card" class="btn" type="primary">下一步</van-button>
  </div>
</template>

<script>
export default {
  data () {
    return {
      username: this.$route.params.utel,
      password: ''
    }
  },
  created () {
    // console.log('设置新密码', this.username)
  },
  methods: {
    async sub_card () {
      if (this.password === '') return this.$Toast('请输入密码')
      const res = await this.$http.post('/changepassword', {
        utel: this.username,
        pwd: this.password
      })
      const {
        data: { status, message }
      } = res
      if (status !== 0) return this.$Toast(message)
      this.$Toast(message)
      // this.$router.push('/mime/' + this.username)

      setTimeout(() => {
        this.$router.push('/login')
      }, 1000)
    }
  },
  computed: {
    isflay () {
      return !/^1[3-9]{2}\d{8}$/g.test(this.username)
    }
  }
}
</script>

<style lang='less' scoped>
.iphone {
  height: 619px;
  background: skyblue;
  h2 {
    text-align: center;
  }
  .btn {
    width: 100%;
    margin: 20px 0 15px 0;
  }
}
</style>
